package com.example.graduation.controller.Hr;

import com.example.graduation.entity.dto.MapDto;
import com.example.graduation.mapper.MapDtoMapper;
import com.example.graduation.service.CompanyService;
import com.example.graduation.service.HrService;
import com.example.graduation.util.ShiroUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.Iterator;

/**
 * @author Jeffery
 * Hr权限
 */
@Controller
@RequestMapping("/hr")
@Slf4j(topic = "HrController")
@Api(tags = "带有hr路径的controller")
public class HrController {
    @Resource
    private MapDtoMapper mapDtoMapper;
    @Resource
    private HrService hrService;
    @Resource
    private CompanyService companyService;

    /**
     * 校验hr邮箱是否已经注册
     *
     * @param email email
     * @return html
     */
    @PostMapping("/bindStep1")
    @ApiOperation("绑定步骤1")
    @ApiImplicitParam(name = "email", value = "邮箱地址")
    public String bindStep1(@RequestParam("email") String email,
                            Model model) {
        MapDto mapDto = mapDtoMapper.checkHrIsRegister(email);
        log.info("mapDto不为空？  : {}", mapDto != null);
        if (mapDto != null) {
            model.addAttribute("hr_msg", "请完成HR认证，再进行发布职位！");
            model.addAttribute("email", ShiroUtil.getUserId());
            return "bindstep1";
        } else {
            //将当前邮箱携带前往bindstep2.html
            model.addAttribute("hr_email", email);
            model.addAttribute("email", ShiroUtil.getUserId());
            return "bindstep2";
        }
    }

    /**
     * hr认证第二步
     *
     * @param email hr邮箱
     * @return html
     */
    @PostMapping("/bindstep2")
    public String bindStep2(@RequestParam("companyName") String companyName,
                            @RequestParam("email") String email,
                            Model model) {
        return "";
    }
}
